package com.nbufe.domain.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.nbufe.domain.dto.process.AddEmissionOriginDto;
import com.nbufe.enums.AppHttpCodeEnum;
import com.nbufe.exception.SystemException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Date;

/**
 * (EmissionOrigin)表实体类
 *
 * @author makejava
 * @since 2023-12-26 16:01:11
 */
@SuppressWarnings("serial")
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("emission_origin")
public class EmissionOrigin {
    //主键，材料id@TableId
    private Long id;

    //材料名称
    private String name;
    //类型   1固体/液体燃料 2气体燃料
    private Integer type;
    //生产阶段 1燃料燃烧  2工业生产  3电力、热力  4固碳产品
    private String produceStage;
    //创建时间
    private Date createTime;
    //更新时间
    private Date updateTime;
    //逻辑删除
    @TableLogic
    private Integer delFlag;
    //租户id
    private Long tenantId;

    public EmissionOrigin(AddEmissionOriginDto dto) {
        if (CollectionUtils.isEmpty(dto.getSelectStages())) {
            throw new SystemException(AppHttpCodeEnum.NOT_STAGE);
        }
        this.name = dto.getName();
        this.produceStage = JSON.toJSONString(dto.getSelectStages());
    }
}
